package cn.itcast.service.impl;

import cn.itcast.dao.OrderSettingDao;
import cn.itcast.pojo.OrderSetting;
import cn.itcast.service.OrderSettingService;
import cn.itcast.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    private OrderSettingDao orderSettingDao;
    @Override
    public  List<OrderSetting> getOrderSettingsByMonth(String year,String month) {
        try {
            List<OrderSetting> orderSettingDaoAll = this.orderSettingDao.findAll();
            List<OrderSetting> orderSettingAll =new ArrayList<>();
            for (OrderSetting orderSetting : orderSettingDaoAll) {
                /*log.info("orderSetting:{}",orderSetting);*/
                String[] s = DateUtils.parseDate2String(orderSetting.getOrderDate()).split("-");
                if (s[0].equals(year)&&s[1].equals(month)){
                    //将符合页面的日期的数据筛选出来
                    orderSettingAll.add(orderSetting);
                }
            }
            return orderSettingAll;
        } catch (Exception e) {
            e.printStackTrace();
        }
        //没有查询到数据
        return null;
    }

    /**
     * 单日预约设置
     * @param orderDate 日期
     * @param number 预约人数
     * @return
     */
    @Override
    public OrderSetting dayOrderSetting(String orderDate, String number) {
       //id自增,无需考虑
        //将数据保存到t_ordersetting表中,并查询结果返回
        try {
            //将orderDate转换成日期格式
            Date date = DateUtils.parseString2Date(orderDate);

        } catch (Exception e) {
            log.info("e:{}",e);
        }
        return null;
    }
}
